﻿using System;
using System.ComponentModel;
using System.Reflection;

namespace FxSuperCore.Utils
{
	public static class EnumUtils
	{
		/// <summary>
		/// 获取指定枚举上[Description]特性的描述
		/// </summary>
		/// <returns>[Description]特性的描述</returns>
		public static string GetEnumDesc(this Enum enumInstance)
		{
			Type enumType = enumInstance.GetType();
			string name = Enum.GetName(enumType, enumInstance);
			DescriptionAttribute desc = enumType.GetField(name).GetCustomAttribute<DescriptionAttribute>();
			return desc.Description;
		}
	}
}
